<include file="Public/header" />
<title>我的桌面</title>
</head>
<body>
<div class="page-container">
    <h2 class="text-c" style="padding: 0;">采购清单</h2>
    <div class="mt-20">
        <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper no-footer">
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer" id="DataTables_Table_0" role="grid" aria-describedby="DataTables_Table_0_info">
                <tr class="text-c" role="row">
                    <td width="140">单据编号</td>
                    <td width="80">制单人</td>
                    <td width="80">来往单位</td>
                    <td width="80">部门</td>
                    <td width="80">采购人</td>
                    <td width="300" >申请理由</td>
					<td width="300" >跨境账册</td>
                    <td width="40" >操作</td>
                </tr>
                <tr class="text-c" role="row">
                    <td><input title="<{$Think.session.order_no}>" type="text" name="order_no" value="<{$Think.session.order_no}>" class="input-text" disabled></td>
                    <td><input name="making" value="<neq name='home.making' value=''><{$home['making']}><else/><{$Think.session.agent.name}></neq>" type="text" class="input-text"></td>
                    <td><input name="from_company" type="text" class="input-text" value="<{$home['from_company']}>"></td>
                    <td><input name="department" value="<neq name='home.department' value=''><{$home['from_company']}><else/>采购部</neq>" type="text" class="input-text"></td>
                    <td><input name="purchaser" value="<neq name='home.making' value=''><{$home['purchaser']}><else/><{$Think.session.agent.name}></neq>" type="text" class="input-text"></td>
                    <td><textarea name="app_reasons" type="text" class="input-text"><neq name='home.app_reasons' value=''><{$home['app_reasons']}><else/>无</neq></textarea></td>
					<td>
						<select name="manua_id" data-toggle="<{$detail.manua_id}>" class="select">
							<option value="0">请选择</option>
							<foreach name="book_list" item="vo">
								<option value="<{$vo.book_no}>"><{$vo.name}></option>
							</foreach>
						</select>
					</td>
                    <td>
                        <neq name="is_add_list" value="1">
                             <a href="javascript:;" onclick="save()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>保存</a>
                            <else/>
                            无
                        </neq>
                    </td>
                </tr>
            </table>
            <eq name="is_add_list" value="1">
                <div style="margin-top: 12px; margin-bottom: -1px;" class="Huialert Huialert-info"><i class="icon-remove"></i>产品清单</div>
                <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer">
                    <thead>
                    <tr class="text-c" role="row">
                        <th width="80" class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1">ID</th>
                        <th width="200">产品名称</th>
                        <th width="60">类目</th>
                        <th width="75">价格</th>
                        <th width="60">单位名称</th>
                        <th width="60">数量</th>
                        <th width="60">仓库名称</th>
                        <th width="60">预计到货时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    <foreach name="result" item="data">
                        <tr class="text-c odd" role="row">
                            <td class="sorting_1" tabindex="<{$data.id}>"><{$data.id}></td>
                            <td class="text-l"><{$data.name}></td>
                            <td><{$data.category}></td>
                            <td><{$data.price}></td>
                            <td class="td-status"><{$data.unit_name}></td>
                            <td><span class="p_count"><{$data.count}></span></td>
                            <td class="td-status"><{$data.warehouse_name}></td>
                            <td class="td-status"><{$data.expected_time}></td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            <div style="margin-top: 12px; margin-bottom: -1px;" class="Huialert Huialert-info"><i class="icon-remove"></i>产品选择后请“分配仓库”再提交</div>
            <table class="table table-border table-bordered table-bg table-hover table-sort dataTable no-footer">
                <thead>
                <tr class="text-c" role="row">
                    <th width="80" class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1">ID</th>
                    <th width="200">产品名称</th>
                    <th width="60">类目</th>
                    <!-- <th width="75">价格</th> -->
                    <th width="60">第一单位名称</th>
                    <!-- <th width="60">第一单位数量</th> -->
                    <th width="60">第二单位名称</th>
                    <!-- <th width="60">第二单位数量</th> -->
                    <!-- <th width="60">HSCODE</th> -->
                    <th width="60">商品编码</th>
                    <th width="60">操作状态</th>
                    <th width="60" style="min-width: 120px;">操作</th>
                </tr>
                </thead>
                <tbody id="find_id">
                <foreach name="list" item="data">
                    <tr class="text-c odd" role="row">
                        <td class="sorting_1" tabindex="<{$data.id}>"><{$data.id}></td>
                        <td class="text-l"><{$data.name}></td>
                        <td><{$data.category}></td>
                        <!-- <td><{$data.price}></td> -->
                        <td class="td-status"><{$data.unit}></td>
                        <!-- <td><span class="p_count"><{$data.count}></span></td> -->
                        <td class="td-status"><{$data.unit_t}></td>
                        <!-- <td><span class="p_count"><{$data.count_t}></span></td> -->
                        <!-- <td class="td-status"><{$data.hs_code}></td> -->
                        <td class="td-status"><{$data.goods_no}></td>
                        <td class="td-status">
						<if condition="$data.warehouse_code neq ''">
							已分配仓库
						<else />
							未分配仓库
						</if>
						</td>
                        <td>
                            <a href="javascript:;" onclick="warehouse_select('<{$data.id}>')" class="btn btn-primary radius"><i class="Hui-iconfont"></i>仓库分配</a>
                            <a href="javascript:;" onclick="product_del('<{$data.id}>')" class="btn btn-danger radius"><i class="Hui-iconfont"></i>删除</a>
                        </td>
                    </tr>
                </foreach>
                </tbody>
                </table>
            <div class="page">
                <{$page}>
            </div>
            <div style="margin-top: 32px;">
                <a href="javascript:;" onclick="product_add()" class="btn btn-danger radius"><i class="Hui-iconfont"></i>添加产品</a>
                <a href="javascript:;" onclick="ok()" class="btn btn-primary radius"><i class="Hui-iconfont"></i>确定</a>
				<a href="javascript:;" onclick="importexcelAll(<{:I('id')}>)" class="btn btn-primary radius"><i class="Hui-iconfont"></i>批量导入</a>
            </div>
            </eq>
        </div>
    </div>
    </div>
    <include file="Public/footer" />
    <include file="Public/footer_js" />
    <script>
		function importexcelAll(id){
            var index=layer.open({
                type: 2,
                title: '导入数据',
                shadeClose: true,
                shade: 0.5,
                area: ['1000px', '150px'],
                content: '__MODULE__/import/importListproduct/id/'+id+'/'+Math.random() //iframe的url
            });
        }
        function save(){
            $.post('__MODULE__/InboundPlan/addD/'+Math.random(),{
                purchaser:$("input[name=purchaser]").val(),
                app_reasons:$("textarea:eq(0)").val(),
                from_company:$("input[name=from_company]").val(),
                department:$("input[name=department]").val(),
                making:$("input[name=making]").val(),
				manua_id:$("select[name=manua_id]").val(),
            },function (msg){
                if(msg.flag>0){
                   layer.msg('保存成功');
				   <!-- alert(window.location.href+"/id/"+msg.flag); -->
                   window.location.href=window.location.href+"/id/"+msg.flag;
                }else{
                    layer.msg('操作失败，请重试');
                }
            },'json');
        }
        function ok(){
            for(var i=0;i<$("#find_id tr").length;i++){
                if($("#find_id tr").eq(i).attr('tabindex')!=1){
                    layer.msg('存在没有分配仓库的产品');
                    return false;
                }
            }
            $.get('__CONTROLLER__/warehouse_select_session_delete',{},function (msg){
                if(msg.flag==1){
                    layer.msg(msg.data);
                    setTimeout(function (){
                        parent.layer.closeAll();
                        location.href="__CONTROLLER__/index";
                    },800);
                }else{
                    layer.msg('操作失败，请重试');
                }
            },'json');
        }
        function product_add(){
            var index=layer.open({
                type: 2,
                title: '产品添加',
                shadeClose: true,
                shade: 0.5,
                area: ['880px', '800px'],
                content: '__MODULE__/InboundPlan/product_add/'+Math.random() //iframe的url
            });
        }
        function product_del(id){
            $.get('__CONTROLLER__/product_del',{
                id:id,
            },function (msg){
                layer.msg(msg.data);
                if(msg.flag==1){
                    setTimeout(function (){
                        location.reload();
                    },800);
                }
            },'json');
        }
        function warehouse_select(id){
            if(id==''){
                layer.msg('操作有误');
                return false;
            }
            var count="<{$w_count}>";
            var height=200+count*50;
            if(height>$(window).height()){
                height=$(window).height()*0.8;
            }
            var ware=layer.open({
                type: 2,
                title: '仓库添加',
                shadeClose: true,
                shade: 0.8,
                area: ['1280px', 200+count*50+'px'],
                content: '__CONTROLLER__/warehouse_select/id/'+id,
            });
        }
        //////接口 关闭以及分配仓库的  分配按钮
        (function(){
            $.get('__CONTROLLER__/getSelected',{},function (msg){
                if(msg.flag==1){
                    setBtn(msg.data);
                }
            },'json');
        })();
        function setBtn(id){
            var group_id=(id+'').split(',');
            for(var i=0;i<$("#find_id tr").length;i++){
                for(var j=0;j<group_id.length;j++){
                    if($("#find_id tr").eq(i).find("td:eq(0)").attr('tabindex')==group_id[j]){
                        $("#find_id tr").eq(i).find("td:eq(10)").html('已分配仓库');
                        $("#find_id tr").eq(i).attr('tabindex',1);//为1则已经分配仓库
                        //$("#find_id tr").eq(i).find("td:eq(11)").html('无');
                    }
                }
            }
        }
    </script>
</body>
</html>